package com.smit.icastplus;

import android.content.Context;

import com.smit.dvb.DVBManager;
import com.smit.dvb.DVBService;
import com.smit.dvb.IDVBCallback;
import com.smit.dvb.ci.CIControl;
import com.smit.dvb.ci.ICICallback;
import com.smit.dvb.epg.EpgControl;
import com.smit.dvb.epg.IEpgCallback;
import com.smit.dvb.scan.IScanCallback;
import com.smit.dvb.scan.ScanControl;
import com.smit.dvb.service.IServiceCallback;
import com.smit.dvb.service.ServiceControl;
import com.smit.dvb.setup.ISetupCallback;
import com.smit.dvb.setup.SetupControl;
import com.smit.dvb.system.ISystemCallback;
import com.smit.dvb.system.SystemControl;
import com.smit.dvb.update.UpdateControl;

import java.util.List;

/**
 * icastplus DVB管理
 */
public class ICastPlusDVBManager extends DVBManager implements IDVBCallback {

    private static final String TAG = "ICastPlusDVBManager";
    private Context context;
    private ICastPlusDVBService icastPlusDVBService;
    private CIControl ciControl;
    private EpgControl epgControl;
    private ScanControl scanControl;
    private ServiceControl serviceControl;
    private SetupControl setupControl;
    private SystemControl systemControl;
    private UpdateControl updateControl;

    /**
     * 构造函数
     * @param context Android application context
     */
    public ICastPlusDVBManager(Context context) {
        this.context = context;
        icastPlusDVBService = new ICastPlusDVBService(context);
        icastPlusDVBService.initialize();

        ciControl = new CIControl();
        epgControl = new EpgControl();
        scanControl = new ScanControl();
        serviceControl = new ServiceControl();
        setupControl = new SetupControl();
        systemControl = new SystemControl();
        updateControl = new UpdateControl();
    }

    @Override
    public void initialize() {
        icastPlusDVBService.registerDVBCallback(this);
    }

    @Override
    public void release() {
        icastPlusDVBService.removeDVBCallback();
    }

    @Override
    public DVBService getDVBService() {
        return icastPlusDVBService;
    }

    @Override
    public CIControl getCIControl() {
        return ciControl;
    }

    @Override
    public EpgControl getEpgControl() {
        return epgControl;
    }

    @Override
    public ScanControl getScanControl() {
        return scanControl;
    }

    @Override
    public ServiceControl getServiceControl() {
        return serviceControl;
    }

    @Override
    public SetupControl getSetupControl() {
        return setupControl;
    }

    @Override
    public SystemControl getSystemControl() {
        return systemControl;
    }

    @Override
    public UpdateControl getUpdateControl() {
        return updateControl;
    }

    @Override
    public void handleCICallbackMsg(int msg, Object param) {
        List<ICICallback> callbackList = ciControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (ICICallback callback : callbackList) {
                callback.handleCICallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleEpgCallbackMsg(int msg, Object param) {
        List<IEpgCallback> callbackList = epgControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (IEpgCallback callback : callbackList) {
                callback.handleEpgCallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleScanCallbackMsg(int msg, Object param) {
        List<IScanCallback> callbackList = scanControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (IScanCallback callback : callbackList) {
                callback.handleScanCallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleServiceCallbackMsg(int msg, Object param) {
        List<IServiceCallback> callbackList = serviceControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (IServiceCallback callback : callbackList) {
                callback.handleServiceCallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleSetupCallbackMsg(int msg, Object param) {
        List<ISetupCallback> callbackList = setupControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (ISetupCallback callback : callbackList) {
                callback.handleSetupCallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleSystemCallbackMsg(int msg, Object param) {
        List<ISystemCallback> callbackList = systemControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (ISystemCallback callback : callbackList) {
                callback.handleSystemCallbackMsg(msg, param);
            }
        }
    }

    @Override
    public void handleUpdateCallbackMsg(int msg, Object param) {
        List<IScanCallback> callbackList = scanControl.getCallbackList();
        if (callbackList != null && callbackList.size() > 0) {
            for (IScanCallback callback : callbackList) {
                callback.handleScanCallbackMsg(msg, param);
            }
        }
    }

}